<template>
    <div class="activity-wrap">
        <div id="shouldfix">
            <activity :detail='activity' :publish="publish"></activity>
            <apply :activity='activity' v-if="activity" @showpost="showpost"></apply>
        </div>
        <post-info :postInfo="signInfo" v-if="showSign"></post-info>
    </div>
</template>

<script>
    import {appService} from '../../service/appService'
    import {actService} from '../../service/activityService'
    import activity from '../../component/detail/activity.vue'
    import apply from '../../component/common/apply.vue'
    import postInfo from '../../component/detail/addInfo.vue'

    export default {
        components: {'activity':activity,'apply':apply,'post-info':postInfo},
        // 添加以下代码
        metaInfo () {
            // console.log(this);
            const title = this.shareData.title || this.activity.activityTitle
            const desc = this.shareData.desc || '运联-活动'
            return {
                title,
                meta: [
                    { vmid: 'description', name: 'description', content: desc },
                    { vmid: 'keyWords', name: 'keyWords', content: '运联'},
                ]
            }
        },
        data () {
            return {
                picHead:this.$store.state.picHead,params:{sortKey:''},
                publish:'',
                signInfo:'',
                ticketInfo:'',
                showSign:false
            }
        },
        asyncData({store,route}) {
            let params = {
                type:20,typeId:route.params.actId
            }
            return Promise.all([
                actService.getactivity(route.params.actId).then(function(res) {
                    if(res){
                        store.state.homeStore.activity = res.data.datas
                    }
                }),
                appService.getshare(params).then(function(res){
                    store.state.shareData=res.data.datas
                })
            ])

        },
        computed: {
            //将存在store中的数据取出
            activity:{
                // getter
                get: function () { return this.$store.state.homeStore.activity || ''},
                // setter
                set: function (newValue) {return newValue}
            },
            shareData: {
                get: function () { return this.$store.state.shareData || []},
                set: function (newValue) {return newValue}
            },
        },
        mounted: function() {
            let that = this
            // console.log(that.activity);
//            that.getactivity()
//            if(appService.checkLogin()){
                that.getPublish()
//            }
//             document.body.removeEventListener('touchmove')

            /*
             * 微信分享设置
             * type查看规则列表写死，
             * text.name为文章标题
             * */
            let share = {
                hasGet:true,
                title:that.shareData.title || that.activity.activityTitle,
                imageUrl: that.shareData.imgUrl,
                brief: that.shareData.desc || '点击查看详情',
                url: that.shareData.dataUrl || window.location.href
            }
            appService.getWxJssdk().then(function () {
                appService.getWxShare(share,'运联-活动列表')
            })

        },
        methods: {
            //获取列表
            getactivity:function () {
                let that = this
                let store = that.$store
                let route = that.$route
                actService.getactivity(route.params.actId).then(function(res){
                    if(!res.data) return
                    store.state.homeStore.activity=res.data.datas
                    that.getPublish()
                })
            },
            getPublish:function () {
                let that = this
                let store = that.$store
                let route = that.$route
                let params={
                    type:2,adminId:store.state.homeStore.activity.publishUserId
                }
                actService.myFollowMain(params).then(function(res){
                    that.publish={
                        id:store.state.homeStore.activity.publishUserId,
                        hostCompany:res.data.datas.hostCompany,
                        hostDesc:res.data.datas.hostDesc,
                        hostLogo:res.data.datas.hostLogo,
                        isFollow:res.data.datas.isFollow,
                    }
                })
            },
            showpost(data){
                this.showSign = true;
                this.signInfo = data.signInfo
                this.ticketInfo = data.ticketInfo
            }
        }
    }
</script>

<style lang="less">
    @import url("../../assets/css/mescroll.min.css");
    .activity-wrap{
        margin-bottom:1.2rem;
    }

</style>
